Class Track

  • All Implemented Interfaces:
    ConsoleScanable

    public class Track
    extends java.lang.Object
    implements ConsoleScanable
    represents a piece of music that has been released on some kind of media (CD, vinyl, video, ...)
    Since:
    ExerciseSheet01
    Version:
    4
    Author:
    Jonas Altrock (ew20b126@technikum-wien.at)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int duration
      the duration of this track in seconds
      private Artist performer
      the artist who performs this track
      private java.lang.String title
      the title of this track.
      private Artist writer
      the artist who wrote this track
      private int year
      the year in which the Track was or will be produced
    • Constructor Summary

      Constructors 
      Constructor Description
      Track()
      creates a default track.
      Track​(java.lang.String title)
      creates a track with a certain title
      Track​(Track other)
      creates a deep copy of a Track
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getDuration()
      gets the duration of this track
      Artist getPerformer()
      returns the performer of this track
      java.lang.String getString()
      returns a formatted String containing all information of this track.
      java.lang.String getTitle()
      gets the title of this track.
      Artist getWriter()
      returns the writer of this track
      int getYear()
      gets the production year of this track
      protected boolean isKnown​(Artist artist)
      Check whether an artist is known.
      boolean scan()
      Guides the user through a process that allows scanning/modifying of this track with a text-based user interface.
      void setDuration​(int duration)
      sets the duration
      void setPerformer​(Artist performer)
      sets the performer of this track
      void setTitle​(java.lang.String title)
      sets the title of this track.
      void setWriter​(Artist writer)
      sets the writer of this track
      void setYear​(int year)
      sets the production year of this track
      java.lang.String toString()
      returns a String representation of this track
      boolean writerIsKnown()
      this getter is used to check if the writer of this Track is known.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • duration

        private int duration
        the duration of this track in seconds

        the duration is a non-negative number, duration 0 (zero) represents unknown duration

      • performer

        private Artist performer
        the artist who performs this track

        the performer cannot be null

      • title

        private java.lang.String title
        the title of this track.
      • writer

        private Artist writer
        the artist who wrote this track

        the writer cannot be null

      • year

        private int year
        the year in which the Track was or will be produced

        valid years are between 1900-2999

    • Constructor Detail

      • Track

        public Track()
        creates a default track.

        a default track has the following values:

        • unknown title
        • duration 0
        • default writer and performer
        • year 1900
      • Track

        public Track​(java.lang.String title)
        creates a track with a certain title

        the resulting track has the specified title, all other values are default

        Parameters:
        title - the title of this track
      • Track

        public Track​(Track other)
        creates a deep copy of a Track
        Parameters:
        other - the track to copy
    • Method Detail

      • getDuration

        public int getDuration()
        gets the duration of this track
        Returns:
        the duration
      • getPerformer

        public Artist getPerformer()
        returns the performer of this track
        Returns:
        the performer
      • getTitle

        public java.lang.String getTitle()
        gets the title of this track. if the title is not known (null) "unknown title" is returned (without quotes)
        Returns:
        the title
      • getWriter

        public Artist getWriter()
        returns the writer of this track
        Returns:
        the writer
      • getYear

        public int getYear()
        gets the production year of this track
        Returns:
        the year
      • setDuration

        public void setDuration​(int duration)
        sets the duration

        a negative value is ignored, the object remains unchanged

        Parameters:
        duration - the duration to set
      • setPerformer

        public void setPerformer​(Artist performer)
        sets the performer of this track

        null arguments are ignored

        Parameters:
        performer - the performer to set
      • setTitle

        public void setTitle​(java.lang.String title)
        sets the title of this track.
        Parameters:
        title - the title to set
      • setWriter

        public void setWriter​(Artist writer)
        sets the writer of this track

        null arguments are ignored

        Parameters:
        writer - the writer to set
      • setYear

        public void setYear​(int year)
        sets the production year of this track

        valid years are between 1900 and 2999

        other values are ignored, the object remains unchanged

        Parameters:
        year - the year to set
      • writerIsKnown

        public boolean writerIsKnown()
        this getter is used to check if the writer of this Track is known.
        Returns:
        true if the writer of this track is known (and has a name), false otherwise.
      • isKnown

        protected boolean isKnown​(Artist artist)
        Check whether an artist is known.
        Parameters:
        artist - the artist to check
        Returns:
        whether the artist is known or not
      • getString

        public java.lang.String getString()
        returns a formatted String containing all information of this track.

        the String representation is (without quotes):

         "title by writer performed by performer (min:sec)"
         

        where

        • title stands for the title (exactly 10 chars wide) if not set, return unknown
        • writer stands for the writer name (exactly 10 chars wide, right justified)
        • performer stands for the performer name (exactly 10 chars wide, right justified)
        • min is the duration's amount of full minutes (at least two digits, leading zeros)
        • sec is the duration's remaining amount of seconds (at least two digits, leading zeros)
        Returns:
        a String representation of this track
      • toString

        public java.lang.String toString()
        returns a String representation of this track

        the string representation of this track is described in getString()

        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • scan

        public boolean scan()
        Guides the user through a process that allows scanning/modifying of this track with a text-based user interface.

        This method allows modification of the following fields, in the order listed:

        • title
        • duration

        For each modifiable field the process is the following:

        • field name and current value are displayed
        • new value is read and validated

        if input is valid, field is set, otherwise a short message is shown and input of this field is repeated.

        Old values can be kept for all fields by entering an empty string. The operation cannot be cancelled, instead the user must keep all former values by repeatedly entering empty strings.

        Specified by:
        scan in interface ConsoleScanable
        Returns:
        whether this object was altered or not